package datastructure.array


import redirectSystemIn
import redirectSystemOut
import org.junit.jupiter.api.Test
import java.util.*

class MatchingStringsTests {
    @Test
    fun matchingStringsTest() {
        redirectSystemIn(this.javaClass) {
            val scan = Scanner(System.`in`)
            redirectSystemOut {
                while (scan.hasNextLine()) {
                    val stringsCount = scan.nextLine().trim().toInt()

                    val strings = Array<String>(stringsCount) { "" }
                    for (i in 0 until stringsCount) {
                        val stringsItem = scan.nextLine()
                        strings[i] = stringsItem
                    }

                    val queriesCount = scan.nextLine().trim().toInt()

                    val queries = Array<String>(queriesCount) { "" }
                    for (i in 0 until queriesCount) {
                        val queriesItem = scan.nextLine()
                        queries[i] = queriesItem
                    }

                    val res = matchingStrings(strings, queries)

                    println(res.joinToString("\n"))
                    for (i in 0 until queriesCount) {
                        it.add(scan.nextLine().trim())
                    }
                }
            }
        }
    }
}